<template>
	<view class="userInfo">
		<view class="b-f p-a-d">
			
		<view class="flex flex-y-c flex-x-b h">
			<view class="flex">
				<view class="img_a">
					<image src="../../static/1.png" mode=""></image>
				</view>
				<view class="name">
					用户头像
				</view>
			</view>
			<view class="header_img" @click="chooseImage">
				<image :src="imageUrl" mode=""></image>
			</view>
		</view>
		<view class="line">
			
		</view>
		<view class="flex flex-y-c flex-x-b h">
			<view class="flex">
			<view class="img_a">
				<image src="../../static/2.png" mode=""></image>
			</view>
			<view class="name">
				用户姓名
			</view>
			</view>
			<view class="">
				{{userInfo.nick_name?userInfo.nick_name:''}}
			</view>
		</view>
		<view class="line">
			
		</view>
		<view class="flex flex-y-c flex-x-b h">
			<view class="flex">
				
			<view class="img_a">
				<image src="../../static/3.png" mode=""></image>
			</view>
			<view class="name">
				宝妈手机号
			</view>
			</view>
			<view class="">
				{{userInfo.member.MotherPhone?userInfo.member.MotherPhone:''}}
			</view>
		</view>
		<view class="line">
			
		</view>
		<view class="flex flex-y-c flex-x-b h">
			<view class="flex">
				
			<view class="img_a">
				<image src="../../static/2.png" mode=""></image>
			</view>
			<view class="name">
				宝贝姓名
			</view>
			</view>
			<view class="">
				{{userInfo.member.ChildName?userInfo.member.ChildName:''}}
			</view>
		</view>
		<view class="line">
			
		</view>
		<view class="flex flex-y-c flex-x-b h">
			<view class="flex">
				
			<view class="img_a">
				<image src="../../static/4.png" mode=""></image>
			</view>
			<view class="name">
				宝贝性别
			</view>
			</view>
			<view class="">
				{{userInfo.member.ChildSex?userInfo.member.ChildSex:''}}
			</view>
		</view>
		<view class="line">
			
		</view>
		<view class="flex flex-y-c flex-x-b h">
			<view class="flex">
				
			<view class="img_a">
				<image src="../../static/5.png" mode=""></image>
			</view>
			<view class="name">
				宝贝生日
			</view>
			</view>
			<view class="">
				{{userInfo.member.ChildBirthday?userInfo.member.ChildBirthday:''}}
			</view>
		</view>
		<view class="line">
			
		</view>
		<view class="flex flex-y-c flex-x-b h">
			<view class="flex">
				
			<view class="img_a">
				<image src="../../static/6.png" mode=""></image>
			</view>
			<view class="name">
				存款余额
			</view>
			</view>	
			<view class="">
				{{userInfo.member.SaveMoney?userInfo.member.SaveMoney:''}}
			</view>
		</view>
		<view class="line">
			
		</view>
		</view>
		
		<view class="p-a-d flex flex-y-c f-22">
			<image src="../../static/icon.png" mode="" style="width: 20rpx;height: 20rpx;margin-right: 20rpx;"></image>
			如未显示会员信息，请联系专属客服 <span @click='getphone'>0351-2347114</span> 
		</view>
	</view>
	
</template>

<script>
	import * as Api from '@/api/pony'
	import * as UserApi from '@/api/user'
	import * as UploadApi from '@/api/upload'
	export default {
		data(){
			return {
				errCode: 0,
				errMsg: '',
				userInfo:{},
				imageList:[],
				imageUrl:'../../static/img.png'
			}
		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			getphone(){
				uni.makePhoneCall({
					phoneNumber: '0351-2347114', //电话号码
					success: function(e) {
						console.log(e);
					},
					fail: function(e) {
						console.log(e);
							
					},
				})
			},
			getUser() {
				Api.getMember(
					{phone:'15676131098'}
				)
				  .then(result => {
				    // 合并新数据
					console.log(result)
				    const newList = result.data.list
				    // app.list.data = getMoreListData(newList, app.list, pageNo)
				    // resolve(newList)
				  })
			},
			
			getUserInfo(){
				let app=this
				UserApi.info()
				.then(result => {
					// 设置页面数据
					console.log(result.data.userInfo)
					app.userInfo = result.data.userInfo
					// console.log(app.userInfo)
				})
			},
			chooseImage() {
			  const app = this
			  const oldImageList = app.imageList
			  // 选择图片
			  uni.chooseImage({
			    count: 1,
			    sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
			    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
			    success({ tempFiles }) {
			      // tempFiles = [{path:'xxx', size:100}]
			      app.imageList = oldImageList.concat(tempFiles)
				  console.log(app.imageList,111)
				  app.imageUrl=app.imageList[0].path
				  app.uploadFile()
			    }
			  });
			},
			uploadFile() {
			  const app = this
			  const { imageList } = app
			  // 批量上传
			  return new Promise((resolve, reject) => {
			    if (imageList.length > 0) {
			      UploadApi.image(imageList)
			        .then(fileIds => {
						console.log(imageList,111)
						Api.changeAvatar({
							avatar_id:fileIds.toString()
						})
						.then(result => {
							console.log(result)
							uni.showToast({
								title:result.message
							})
						})
			          resolve(fileIds)
			        })
			        .catch(reject)
			    } else {
			      resolve()
			    }
			  })
			}
		},
		
	}
</script>

<style>
	.flex{
		display: flex;
	}
	.flex-y-c{
		align-items: center;
	}
	.flex-x-a{
		justify-content: space-around;
	}
	.flex-x-b{
		justify-content: space-between;
	}
	.userInfo{
		/* padding: 20rpx; */
		background-color: #fff;
		margin-top:30rpx;
		min-height: 100vh;
		background-image: url('http://tu.qixiaocheng.com/xiaomahuanteng/login_bg.png');
		background-repeat: no-repeat;
		background-size: cover;
	}
	
	.name{
		width: 150rpx;
		margin-right: 30rpx;
	}
	
	.line{
		width: 100%;
		height: 1rpx;
		background: #F4F4F4;
		margin:20rpx 0;
	}
	.h{
		height: 80rpx;
	}
	
	.img_a{
		width: 40rpx;
		height: 40rpx;
		margin-right: 20rpx;
	}
	.img_a image{
		width: 100%;
		height: 100%;
	}
	
	.header_img{
		width: 60rpx;
		height: 60rpx;
	}
	.header_img image{
		width: 100%;
		height: 100%;
	}
	
	.p-a-d{
		padding: 20rpx;
	}
</style>